package com.atguigu.edu.controller;


import com.atguigu.common.util.R;
import com.atguigu.edu.service.EduSubjectService;
import com.atguigu.edu.entity.vo.tree.EduSubjectNode;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author alexzshl
 * @since 2021-05-04
 */
@RestController
@RequestMapping("/api/edu/subject")
@CrossOrigin
public class EduSubjectController {

    @Resource
    private EduSubjectService eduSubjectService;

    @PostMapping("/upload")
    public R addSubject(MultipartFile file) {
        System.out.println("==============================================================================");
        System.out.println(file.getContentType());
        eduSubjectService.saveSubjectFromFile(file);
        return R.ok();
    }

    @GetMapping("/list")
    public R getSubjectList() {
        List<EduSubjectNode> data = eduSubjectService.getSubjectTree();
        return R.ok().data("result", data).data("items", data).data("list", data);
    }
}

